package com.ysqcould.web.controller.Community;


import com.ysqcould.Community.domain.Charity;
import com.ysqcould.Community.domain.VolActivity;
import com.ysqcould.Community.service.IVolActivityService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 义工活动信息Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/Community/activity")
public class VolActivityController extends BaseController
{
    @Autowired
    private IVolActivityService volActivityService;

    /**
     * 查询义工活动信息列表
     */
    @PreAuthorize("@ss.hasPermi('Community:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(VolActivity volActivity)
    {
        startPage();
        List<VolActivity> list = volActivityService.selectVolActivityList(volActivity);
        return getDataTable(list);
    }

    /**
     * 导出义工活动信息列表
     */
    @PreAuthorize("@ss.hasPermi('Community:activity:export')")
    @Log(title = "义工活动信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VolActivity volActivity)
    {
        List<VolActivity> list = volActivityService.selectVolActivityList(volActivity);
        ExcelUtil<VolActivity> util = new ExcelUtil<VolActivity>(VolActivity.class);
        util.exportExcel(response, list, "义工活动信息数据");
    }

    /**
     * 获取义工活动信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('Community:activity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(volActivityService.selectVolActivityById(id));
    }

    /**
     * 新增义工活动信息
     */
    @PreAuthorize("@ss.hasPermi('Community:activity:add')")
    @Log(title = "义工活动信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VolActivity volActivity)
    {
        volActivity.setAsId(getUserId());
        return toAjax(volActivityService.insertVolActivity(volActivity));
    }

    /**
     * 修改义工活动信息
     */
    @PreAuthorize("@ss.hasPermi('Community:activity:edit')")
    @Log(title = "义工活动信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VolActivity volActivity)
    {
        return toAjax(volActivityService.updateVolActivity(volActivity));
    }

    /**
     * 删除义工活动信息
     */
    @PreAuthorize("@ss.hasPermi('Community:activity:remove')")
    @Log(title = "义工活动信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(volActivityService.deleteVolActivityByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody VolActivity activity)
    {
        return toAjax(volActivityService.updateStatus(activity));
    }
}
